<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件驱动</title>
    <style>
        input {
            display: block;
        }
    </style>
</head>

<body>
    商品：<input type="text" id="sum">
    数量：<input type="text" id="price">
    小计：<input type="text" id="total">
</body>

<script>
    let goodssum = document.getElementById("sum");
    let goodsprice = document.getElementById("price");
    let total = document.getElementById("total");


    goodssum.oninput = function () {
        total.value = goodssum.value * goodsprice.value;
    }

    goodsprice.oninput = function () {
        total.value = goodssum.value * goodsprice.value;
    }

</script>

</html>